var app = getApp()
Page({
  data: {
    footer: {
      i_home: "../images/button1.png",
      i_tel: "../images/button2on.png",
      i_chat: "../images/button4.png",
      i_add: "../images/button5.png",
    
    },
    cateId: 0,
    arraydetail: [],
    subtype: [],
    author: 'Lotus'
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.shopName,
      path: '/pages/index/producttype?fromInviteCode=' + app.globalData.myInviteCode,
      success: function (res) {
        //console.log("转发成功");
      }
    }
  },
  clicktype: function (e) {
    var that = this;
    var aId = e.target.dataset.id;
    that.setData({
      cateId: aId
    })
    that.getlist();
  },
  getlist: function () {

    var that = this; 
    var service = 'Farm.getCateMore';
    var indexDisplay = 0;
    //console.log("appId:" + app.globalData.APPID);
    //console.log("indexDisplay:" + indexDisplay);

    app.util.request({
      'url': 'entry/wxapp/getcategory',
   
      success: function (res) {
        console.log(that);
        //console.log("success:" + res.data.data);
        var cate_gory = res.data.data.category;
   
        var arraydetail = res.data.data.category;
     
          var subtype2 = [];
          var cateId = that.data.cateId; console.log(cateId);
          for (var i in arraydetail) {
           
            if (cateId == 0) {
             
              cateId = arraydetail[i].id; 
            }
            if (arraydetail[i].id == cateId) {
              
            
              if (arraydetail[i].children.length > 0) {
               
                subtype2 = arraydetail[i].children;
                that.setData({ subtype: subtype2 });
           

                cateId = arraydetail[i].id;
              }
              arraydetail[i].css = 'active';
            } else {
              arraydetail[i].css = 'othertype';
              console.log(arraydetail[i].children);

              that.setData({ subtype: subtype2 });
            
            }
           
          }
          
         

        that.setData({
          arraydetail: arraydetail ,

        })
     
      }
    })



  },
  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode = options.fromInviteCode;
    }
    app.appstart();
    if (options.cateId) {
      this.setData({ cateId: options.cateId });
    }
    this.getlist();
  }
})